package com.tnr.scgcxx.service.safty.saftyimpl;

import com.tnr.scgcxx.base.CurrUser;
import com.tnr.scgcxx.dao.safty.LoginDao;
import com.tnr.scgcxx.dto.UserDto;
import com.tnr.scgcxx.exception.BusinessException;
import com.tnr.scgcxx.exception.SysException;
import com.tnr.scgcxx.model.User;
import com.tnr.scgcxx.service.safty.LoginServce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class LoginServiceImpl implements LoginServce {
   @Autowired
    private LoginDao loginDao;

    @Override
    public CurrUser checklogin(UserDto userDto) {

        User user= null;
        try {
            user = loginDao.findUserByNameandPwd(userDto);
        } catch (Exception e) {
            throw new SysException("系统错误");
        }
        if(user==null){
            throw new BusinessException("账号或密码错误");
        }
        return new CurrUser(user.getU_id(),user.getU_name());
    }
}
